from collections import defaultdict


def four_sums(a, b, c, d):
    dict1 = two_sums(a, b)
    dict2 = two_sums(c, d)
    result = 0
    for k1 in dict1:
        result+=dict1.get(k1) * dict2.get(-k1, 0)
    return result

def two_sums(a, b):
    result = defaultdict(int)
    for n1 in a:
        for n2 in b:
            result[n1+n2]+=1
    return result

A = [ 1, 2]
B = [-2,-1]
C = [-1, 2]
D = [ 0, 2]

print(four_sums(A, B, C, D))